package com.xx.questionnaire.cis.UserOperation.Register.servlet;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.xx.questionnaire.cis.UserInfo.entity.User;
import com.xx.questionnaire.cis.UserOperation.Register.services.RegisterIService;
import com.xx.questionnaire.cis.UserOperation.Register.services.RegisterService;


/**
 * 
 */
public class RegisterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	static Logger log = Logger.getLogger(RegisterServlet.class);
	private User user=null;
	private RegisterIService register = null;
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
		user = null;
	}
	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public RegisterServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see Servlet#init(ServletConfig)
	 */
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
	}

	 
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		log.info(Thread.currentThread().getStackTrace()[1].getMethodName()+"被调用！");
		String username = request.getParameter("username");
		String password = request.getParameter("password1");
		String password2 = request.getParameter("password2");
		String email = request.getParameter("email");
		String website = request.getParameter("website");
		Integer age = Integer.parseInt(request.getParameter("age"));
		String description = request.getParameter("description");
		log.info("用户名username："+username);
		log.info("密码password："+password);
		log.info("重复密码password2："+password2);
		log.info("邮箱email:"+email);
		log.info("个人网址website:"+website);
		log.info("年龄age:"+age);
		log.info("描述description:"+description);
		register = new RegisterService();
		if(!username.equals("")&&!password.equals("")&&!password2.equals("")&&!email.equals("")&&age!=null){
			user = new User(username,password);
		}
	 boolean bl = register.RegisterBoolean(user);
	 log.info("此账户在数据库中是否存在："+bl);
	 
	}

	 

}
